package com.mxchip.livestarmobile.mobile.util.widget.opengl.util;

import android.graphics.RectF;
import android.opengl.Matrix;

public class MatrixUtil {
    public static void calculateMatrix(float[] mMVP, RectF rectF, float screenWidth, float screenHeight, int index) {
        Matrix.setIdentityM(mMVP, 0);
        float scaleX = 1f / 4f;
        float scaleY = 1f / 4f;
        float ratioX = (rectF.left - .5f * (1 - scaleX) * screenWidth) / rectF.width();
        float ratioY = (rectF.top - .5f * (1 + scaleY) * screenHeight) / rectF.height();
        Matrix.scaleM(mMVP, 0, scaleX, scaleY, 0f);
        switch (index) {
            case 1:
                Matrix.translateM(mMVP, 0, ratioX * 2, -1.4916667f * 2, 0f);
                break;
            case 2:
                Matrix.translateM(mMVP, 0, ratioX * 2, -1, 0f);
                break;
            case 3:
                Matrix.translateM(mMVP, 0, ratioX * 2, 1, 0f);
                break;
            case 4:
                Matrix.translateM(mMVP, 0, ratioX * 2, 1.4916667f * 2, 0f);
                break;
            case 5:
                Matrix.translateM(mMVP, 0, -ratioX * 2, -ratioY * 2, 0f);
                break;
            case 6:
                Matrix.translateM(mMVP, 0, -ratioX * 2, -ratioY , 0f);
                break;

            default:
                break;
        }

    }


}
